
public class ArrayDemo3 {

	public static void main(String[] args) {
		
		// Create and assign values to an array at the same time
		String[] names = {"Henry", "Siva", "Jaya", "Manisha"};
		
		
		System.out.println("5th name = " + names[3]);
		
		// for each loop is used to read from an array or from a collection. It can't be used in any other scenario. It helps you to iterate 
		//through an array without having much code. It was introduced in JDK 1.5
		for(String name : names) // This means for each String the variable name in the array names. In this array for each element name, it is
								 // storing names
		{
			System.out.println("Name = " + name);
		}
		
		// for loop
		for(int i=0; i<names.length; i++)
		{
			
			System.out.println("Name = " + names[i]); 
		}
		
		// for loop another way. This is a traditional way of doing for loop.
		for(int i=0; i<names.length; i++)
		{
			String name = names[i];
			System.out.println("Name = " + name); 
			}
	}
}
